<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="200px">
      <el-form-item label="应用comId" prop="comId">
        <el-input v-model="form.comId" placeholder="请输入应用com_id" />
      </el-form-item>
      <el-form-item label="应用corpId" prop="corpId">
        <el-input v-model="form.corpId" placeholder="请输入应用corpId" />
      </el-form-item>
      <el-form-item label="应用APPID" prop="appid">
        <el-input v-model="form.appid" placeholder="请输入应用APPID" />
      </el-form-item>
      <el-form-item label="应用APPSecret" prop="appSecret">
        <el-input v-model="form.appSecret" placeholder="请输入应用APPSecret" />
      </el-form-item>
      <el-form-item label="接口域名" prop="host">
        <el-input v-model="form.host" placeholder="请输入接口域名" />
      </el-form-item>
      <el-form-item label="本地人脸URL" prop="localFaceUrl">
        <el-input v-model="form.localFaceUrl" placeholder="请输入本地人脸URL" />
      </el-form-item>
      <el-form-item label="推送数据条数(条)" prop="pushLimit">
        <el-input v-model="form.pushLimit" placeholder="请输入推送数据条数" />
      </el-form-item>
      <el-form-item label="拉取数据条数(条)" prop="pullLimit">
        <el-input v-model="form.pullLimit" placeholder="请输入拉取数据条数" />
      </el-form-item>
      <el-form-item label="数据模块" prop="module">
        <el-input v-model="form.module" placeholder="请输入数据模块" />
      </el-form-item>
      <el-form-item label="设备巡检时间(分钟)" prop="patrolTime">
        <el-input v-model="form.patrolTime" placeholder="请输入设备巡检时间(分钟为单位)" />
      </el-form-item>
      <el-form-item label="识别时间间距(分钟)" prop="detectTimeIntervals">
        <el-input v-model="form.detectTimeIntervals" placeholder="请输入识别时间间距(分钟为单位)" />
      </el-form-item>
      <el-form-item label="是否推送消息" prop="isPushMessage">
        <el-radio-group v-model="form.isPushMessage">
          <el-radio :label="1">启用</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="使用人脸队列" prop="isDetectList">
        <el-radio-group v-model="form.isDetectList">
          <el-radio :label="1">启用</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="启用服务" prop="enableService">
        <el-radio-group v-model="form.enableService">
          <el-radio :label="1">启用</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { listConfig, getConfig, delConfig, addConfig, updateConfig } from "@/api/wisdom/config";

export default {
  name: "Config",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表单参数
      form: {
        id: 1,
        comId: null,
        corpId: null,
        host: null,
        appid: null,
        appSecret: null,
        pushLimit: null,
        pullLimit: null,
        isPushMessage: 0,
        isDetectList: 0,
        enableService: 0,
        module: null,
        patrolTime: 5,
        detectTimeIntervals: 5,
        localFaceUrl: null,
      },
    };
  },
  created() {
    this.getConfig();
  },
  methods: {
    /** 查询参数配置列表 */
    getConfig() {
      this.loading = true;
      getConfig(1).then(response => {
        this.form = response.data;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateConfig(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addConfig(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
<style scoped>
.dialog-footer {
  text-align: center;
  margin-top: 20px;
}
</style>
